<template>
  <view>
    <view class="list_wrap">
      <!-- 发票列表 -->
      <InfoList
        v-if="hasInvoiceList"
        :list="dataList"
        @select-item="selectInvoice"
      />
      <!-- 空列表 -->
      <EmptyList v-else />
    </view>
    <!-- 底部按钮栏 -->
    <PageFooterBar
      only-btn
      :btn-list="btnList"
      @click="handleAddInvoice"
    />
  </view>
</template>
<script>
import PageFooterBar from '@/components/page-footer-bar'
import EmptyList from './components/Empty'
import InfoList from './components/InfoList'
import { queryInvoice } from '@/api/yc_invoice'
export default {
  components: {
    PageFooterBar,
    EmptyList,
    InfoList
  },
  data() {
    return {
      btnList: [{ name: '添加发票抬头' }],
      dataList: [], // 列表数据
      accountType: '', // 账号类型
    }
  },
  computed: {
    // 有发票抬头列表数据
    hasInvoiceList() {
      return this.dataList.length > 0
    },
    // crm信息
    crmCustomerInfos() {
      if (Array.isArray(this.vuex_crmCustomerInfos)) {
        return this.vuex_crmCustomerInfos[0]
      }
      return this.vuex_crmCustomerInfos
    }
  },
  onShow() {
    this.getInvoiceList()
  },
  // 下拉刷新请求
  onPullDownRefresh() {
    this.getInvoiceList()
  },
  methods: {
    // 添加发票抬头
    handleAddInvoice() {
      uni.navigateTo({
        url: `/invoiceManage/updateInvoice?type=add`
      })
    },
    // 选择发票
    selectInvoice(item) {
      uni.navigateTo({
        url: `/invoiceManage/updateInvoice?type=edit&invoiceDetail=${JSON.stringify(item)}`
      })
    },
    // 获取发票抬头列表
    async getInvoiceList() {
      const params = {
        memberId: this.vuex_memberInfo.memberId,
        customerCode: this.crmCustomerInfos?.customerCode,
      }
      const res = await queryInvoice(params)
      if (res.code == 0) {
        this.dataList = res.data.invoiceIftResList
      } else {
        this.$u.toast(res.msg)
      }
    },
  }
}
</script>
<style lang="scss" scoped>
.list_wrap {
  width: 100%;
  height: 100%;
}
</style>
